﻿using Delonix_Regia_Hotel.Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Delonix_Regia_Hotel
{
    public partial class EnterGuestDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            DropDownList1.Text = "Please Select";
            string roomtype = Request.QueryString["roomtype"];
            Label2.Text = roomtype;
            string price = Request.QueryString["price"];
            Label1.Text = price;
            string dateofarrival = (string)Session["dateofarrival"];
            Label4.Text = dateofarrival ;
            string nights = (string)Session["nights"];
            Label6.Text = nights;
            string dateofdeparture = (string)Session["dateofdeparture"];
            Label5.Text = dateofdeparture;
            string rooms = (string)Session["rooms"];
            Label3.Text = rooms;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.Text == "Please Select." || TextBox1.Text == "" || TextBox2.Text == "" || TextBox8.Text == "" || TextBox9.Text == "" || TextBox10.Text == "" || TextBox3.Text == "" || DropDownList2.SelectedValue == "Country" || TextBox4.Text == "" && TextBox5.Text == "" || DropDownList5.SelectedValue == "Please Select." || TextBox7.Text == "" || DropDownList3.SelectedValue == "Month" || DropDownList4.SelectedValue == "Year")
            {
                Label7.Text = "*Please fill in required blanks!";
            }
            else
            {
                string title = DropDownList1.Text;
                string firstname = TextBox1.Text;
                string lastname = TextBox2.Text;
                string idenNo = TextBox8.Text;
                string homeadd = TextBox9.Text;
                string mailadd = TextBox10.Text;
                string email = TextBox3.Text;
                string contact = DropDownList2.SelectedValue + " " + TextBox4.Text + " " + TextBox5.Text;
                string cardtype = DropDownList5.SelectedValue;
                string cardno = TextBox7.Text;
                string cardexpiry = DropDownList3.SelectedValue + " " + DropDownList4.SelectedValue;
                string price = Label1.Text;
                string roomtype = Label2.Text;
                string dateofarrival = Label4.Text;
                string nights = Label6.Text;
                string dateofdeparture = Label5.Text;
                string rooms = Label3.Text;

                Guest guest = new Guest();
                guest.Fname = firstname;
                guest.Lname = lastname;
                guest.Ic = idenNo;
                guest.Contactnum = contact;
                guest.Email = email;
                guest.Homeaddress = homeadd;
                guest.Mailingaddress = mailadd;
                guest.Paymethod = cardtype;
                guest.Typesofroom = roomtype;
                guest.Numofrooms = rooms;
                guest.Cardtype = cardtype;
                guest.Cardnum = cardno;
                guest.Expirydate = cardexpiry;
                guest.Periodofstay = nights;
                guest.Dateofarrival = dateofarrival;
                guest.Dateofdeparture = dateofdeparture;
                guest.Price = price;
                if (Guest.CreateGuest(guest) == 1)
                {
                    Session.Remove("dateofarrival");
                    Session.Remove("nights");
                    Session.Remove("dateofdeparture");
                    Session.Remove("rooms");

                    Session["dateofarrival"] = dateofarrival;
                    Session["nights"] = nights;
                    Session["dateofdeparture"] = dateofdeparture;
                    Session["rooms"] = rooms;
                    Session["title"] = title;
                    Session["firstname"] = firstname;
                    Session["lastname"] = lastname;
                    Session["idenNo"] = idenNo;
                    Session["homeadd"] = homeadd;
                    Session["mailadd"] = mailadd;
                    Session["email"] = email;
                    Session["contact"] = contact;
                    Session["cardtype"] = cardtype;
                    Session["cardno"] = cardno;
                    Session["cardexpiry"] = cardexpiry;
                    Server.Transfer("BookingConfirmed.aspx?price=" + price + "&roomtype=" + roomtype);
                }
                else
                {
                    Label7.Text = "Booking Unsuccessful";
                }
            }

        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "American Express";
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "China Union Pay";
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "DINERS";
        }

        protected void ImageButton8_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "DISCOVER";
        }

        protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "JCB";
        }

        protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "MasterCard";
        }

        protected void ImageButton7_Click(object sender, ImageClickEventArgs e)
        {
            DropDownList5.SelectedValue = "Visa";
        }

        protected void LinkButton6_Click(object sender, EventArgs e)
        {
            Session.Remove("dateofarrival");
            Session.Remove("nights");
            Session.Remove("dateofdeparture");
            Session.Remove("rooms");
        }

        protected void LinkButton7_Click(object sender, EventArgs e)
        {
            Session.Remove("dateofarrival");
            Session.Remove("nights");
            Session.Remove("dateofdeparture");
            Session.Remove("rooms");
        }

        protected void LinkButton8_Click(object sender, EventArgs e)
        {
            Session.Remove("dateofarrival");
            Session.Remove("nights");
            Session.Remove("dateofdeparture");
            Session.Remove("rooms");
        }

        protected void LinkButton9_Click(object sender, EventArgs e)
        {
            Session.Remove("dateofarrival");
            Session.Remove("nights");
            Session.Remove("dateofdeparture");
            Session.Remove("rooms");
        }

        protected void LinkButton10_Click(object sender, EventArgs e)
        {
            Session.Remove("dateofarrival");
            Session.Remove("nights");
            Session.Remove("dateofdeparture");
            Session.Remove("rooms");
        }

    }
}